from owlready2 import *

print('1. Thread-based parallel execution of SPARQLqueries')
default_world.set_backend(filename = "owl/my_quadstore.sqlite3", exclusive = False)# 这个参数不行: enable_thread_parallelism = True
default_world.save()

print('2. Executing many SPARQL queries in parallel')
my_onto = get_ontology("XXX ontology IRI here")
queries = [
    default_world.prepare_sparql("""XXX First SPARQL query here""")
    ...,
]
import owlready2.sparql
results = [list(gen) for gen in owlready2.sparql.execute_many(my_onto, queries, queries_params)]

import gevent.hub
gevent_spawn = gevent.hub.get_hub().threadpool.apply_async
results = [list(gen) for gen in owlready.sparql.execute_many(my_onto, queries, queries_params, gevent_spawn)]



print('3. Executing a single SPARQL query in parallel')
query = default_world.prepare_sparql("""XXX SPARQL query here""")
query.execute(spawn = True)

import gevent.hub
gevent_spawn = gevent.hub.get_hub().threadpool.apply_async
query.execute(spawn = gevent_spawn)

